package servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 转发定位资源
 */
public class Servlet03 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //转发定位d1/d2/b.html
        //1.在服务器端 解析第一个/时，会被解析成http://ip:port/项目名，项目名就是配置tomcat时的application context
        //2.在服务器进行转发时，如果没有/，就按照默认的方式(http://ip:port/项目名/)来参考定位
        System.out.println("Servlet03进行转发...");
        req.getRequestDispatcher("/d1/d2/b.html").forward(req, resp);
    }
}
